-- Leafy Glade


function autoexec()
if (get_progress(P_CHORES) == 8) and (get_progress(P_QUEST1) == 0) then
  set_ent_id(0, SENSAR)
else
  set_ent_active(0, 0)
end 
return
end

function refresh()
  return
end

function postexec()
return

end


function zone_handler(zn)
  if (zn == 1) then
    change_map("townx","haunt_exit");

  elseif (zn == 2) then
    change_map("land","haunt_exit") 

  elseif (zn == 3) then
    bubble(HERO1,"I have spent many a night here around a fire with my friend Sensar.")
                            



end
           


end

 
-- 
function entity_handler(en)
  if (en == 0) then
    set_progress(P_QUEST1,1)
    LOC_join_sensar(en)

      
  end
end

function LOC_join_sensar(en)
  local id
  local hero = 0
    bubble(en, "Ahh $0, Its so good to see you.")
    bubble(HERO1, "The same here.")
    bubble(HERO1, "Where have you been? I have only had Mother for company.")
    bubble(en, "hahaha.")
    bubble(en, "Well now...")
    bubble(en, "You have to promise you will keep it secret.") 
    bubble(HERO1, "Of course Sensar!")
    bubble(en, "Well then its time. I have been inducted into a secret opposition group to fight back against the Governor and even the Royal Blue King himself!")
    bubble(en, "And this is where you come in. I was asked to recruit you as well.")
    bubble(HERO1, "Finally something is going right!")
    bubble(en, "There is only one catch to it.")
    bubble(en, "You will need to prove your worthiness.")
    bubble(HERO1, "Even though my Father was...")
    bubble(en, "I have to as well so its no difference.")
    bubble(en, "There is a cave southwest from here that they have asked us to investigate.")
    bubble(en, "We are asked to go and retrieve a key.")
    bubble(HERO1, "Well then lets go.") 
      

  -- Give Sensar her default equipment
  set_all_equip(SENSAR, I_MACE2, I_SHIELD1, I_HELM1, I_ROBE2, I_BAND1, 0)
  id = select_team{SENSAR}
  -- Add the characters that were not selected to the manor
--   add_to_manor(id)

  if (id[1]) then
    set_ent_id(en, id[1])
    set_ent_script(en, "U8K")

    if (id[2]) then
      -- Two heroes were de-selected
      set_ent_id(hero, id[2])
      set_ent_active(hero, 1)

      local x, y = get_ent_tile(en)
      place_ent(hero, x, y - 1)
      bubble(en, "I really would like to have gone with you. Here is the key, have fun without me.")
      set_ent_speed(hero, 4)
      set_ent_speed(en, 4)
      set_ent_script(hero,  "U9K")
      wait_for_entity(hero, en)
    else
      -- One hero was de-selected
      bubble(en, "I really would like to have gone with you. Here is the key, have fun without me.")
      wait_for_entity(en, en)
    end
  end
  set_ent_active(hero, 0)
  set_ent_active(en, 0)
  set_progress(P_PLAYERS, get_progress(P_PLAYERS) + 1)
end